﻿$(document).ready(function () {
    HtmlHelpers.Init();
});

var HtmlHelpers = {
    Init: function () {
        $("input[data-filter='1']").keypress(HtmlHelpers.FilteredTextBox.CheckValue);
    }
};

HtmlHelpers.FilteredTextBox = {
    CheckValue: function (event) {
        var code = event.keyCode || event.which;

        if (event.ctrlKey || event.metaKey || event.altKey || code == 0
            //Text editing characters
            || code ==	33 //Page Up
            || code ==	34 //Page Down
            || code ==	37 //Left arrow
            || code ==	38 //Up arrow
            || code ==	39 //Right arrow
            || code ==	40 //Down arrow            
            || code == 8 //Backspace
            || code == 36 //Home
            || code == 35 //End
            || code == 45 //Insert
            || code == 46 //Delete
            ) {
            return;
        }

        var value = String.fromCharCode(event.which);
        var regex = new RegExp($(this).attr("data-regex"), "");
        
        if (regex.test(value)) {
            event.preventDefault();
        }
    }
};